import akshare as ak
import mplfinance as mpf
import pandas as pd
# 股票代码
stock_code = '000001'
# 获取数据
df = ak.stock_zh_a_hist(symbol=stock_code, period="daily", start_date="20170301", end_date='20230925', adjust="")

# 获取指定字段
df_new = df[['日期','开盘','最高','最低','收盘','成交量']]
# 取前5条数据
# df_new = df_new.head()

# 设置日期为时间类型
df_new2 = df_new.copy()
df_new2['日期'] = pd.to_datetime(df_new['日期'])


# 设置列名
df_new2.columns = ['Date','Open','High','Low','Close','Volume']

# 重新设置索引字段
df_new2.set_index(["Date"], inplace=True)


print(df_new2)

# 绘图
mpf.plot(df_new2.tail(40), type='candle', volume=True, style='yahoo',show_nontrading=True,)

